
<div class="layui-tab layui-tab-brief">


    <div class="tablesize roles" >
        <table id="actDefModel" lay-filter="actDefModel" ></table>

    </div>
</div>
<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="design">查看设计</a>
    <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a>
</script>
<script>
        layui.use(['table', 'layer', 'laydate', 'util'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var util = layui.util;
        var $ = layui.$;
        var setter = layui.setter;
        var laydate = layui.laydate;

        loadTable();

        //第一个实例
        function loadTable(url) {
            table.render({
                elem: '#actDefModel'
                , cellMinWidth: 70
                , title: '流程历史'
                , url: serverPath.workflowPath+setter.workflowLinkPath+'actDefModel/list/history?modelId=${modelId!}'
                , method: 'post'
                , toolbar: '#headerToolsBar'
                , page:true
                , cols: [[
                    {type: 'checkbox', title: '序号',fixed: 'left'}
                    , {field: 'name', title: '标题',  align: 'center'}
                    , {field: 'modelKey', title: '流程定义Key',  align: 'center'}
                    , {field: 'typeName', title: '分类名称',  align: 'center'}
                    , {field: 'version', title: '版本号', align: 'center'}
                    , {field: 'modelComment', title: '修改原因', align: 'center'}
                    , {
                        field: 'createTime', title: '创建时间',  align: 'center', templet: function (d) {
                            return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    , {
                        field: 'updateTime', title: '修改时间',  align: 'center', templet: function (d) {
                            return util.toDateString(d.updateTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    , {
                        field: 'description', title: '描述', align: 'center'
                    }
                    , {fixed: 'right', title: '管理', toolbar: '#bar', width: 200, align: 'center'}
                ]]
            });
        }

        //监听行工具事件
        table.on('tool(actDefModel)', function (obj) {
            var data = obj.data;

            switch (obj.event) {
                //删除 接口
                case 'del':
                    layer.confirm("确认要删除该模型吗？", {title: '删除确认'}, function (index) {
                        $.ajax({
                            url: serverPath.workflowPath + setter.workflowLinkPath + "actDefModel/del",
                            data:{ modelId:data.id,onlyVersion:"true"},
                            type: 'DELETE',
                            dataType:'json',
                            success: function (res) {
                                layer.msg(res.msg, {icon: 1, time: 500});
                                table.reload('actDefModel', {
                                    page: {
                                        curr: 1
                                    }
                                });
                            }
                        });
                        layer.close(index);
                    });
                    break;
                //查看设计 接口
                case 'design':
                    layer.open({
                        type: 2,
                        title: "流程在线设计",
                        shade: 0.3,
                        offset: ['0px', '0px'],
                        left: 200,
                        area: ['100%', '100%'],
                        content: __ctx+'/design.html#/editor/'+data.id,
                        end: function () {
                            table.reload('actDefModel', {
                                page: {
                                    curr: 1
                                }
                            });
                        }
                    });
                    break;
                //明细 接口
                case 'detail':
                    /**
                     * 1、主版本时，该值不存在
                     * 2、历史版本，该值存储主版本的modelId
                     */
                    var re = "${modelIdForReturn}";
                    if(re) {
                        var url = "actDefModel/view/commonSetting?modelId=" + data.id + "&modelIdForReturn="+re;
                    }else{
                        var url = "actDefModel/view/commonSetting?modelId=" + data.id + "&modelIdForReturn=${modelId}";
                    }
                    $(this).attr("href",serverPath.workflowPath + setter.workflowLinkPath+url);
                    break;
            }
        });
    })
</script>
